package com.wofish.goods.service.impl;

import java.util.List;

import com.wofish.goods.mapper.ImageAttachMapper;
import com.wofish.goods.mapper.ImageAttachMapperExpand;
import com.wofish.goods.mapper.ImageMapperExpand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wofish.goods.mapper.ImageMapper;
import com.wofish.goods.domain.Image;
import com.wofish.goods.service.IImageService;
import com.wofish.common.core.text.Convert;

/**
 * 图片 服务层实现
 * 
 * @author wofish
 * @date 2019-06-22
 */
@Slf4j
@Service
public class ImageServiceImpl implements IImageService {
	@Autowired
	private ImageMapper imageMapper;

	@Autowired
	private ImageMapperExpand imageMapperExpand;

	@Autowired
	private ImageAttachMapperExpand imageAttachMapperExpand;

	/**
     * 查询图片信息
     * 
     * @param imageId 图片ID
     * @return 图片信息
     */
    @Override
	public Image selectImageById(String imageId) {
	    return imageMapper.selectImageById(imageId);
	}
	
	/**
     * 查询图片列表
     * 
     * @param image 图片信息
     * @return 图片集合
     */
	@Override
	public List<Image> selectImageList(Image image) {
	    return imageMapper.selectImageList(image);
	}
	
    /**
     * 新增图片
     * 
     * @param image 图片信息
     * @return 结果
     */
	@Override
	public int insertImage(Image image) {
	    return imageMapper.insertImage(image);
	}

	/**
	 * 批量新增图片
	 *
	 * @param list
	 * @return 结果
	 */
	@Override
	public int insertBatchImage(List<Image> list){
		return imageMapper.insertBatchImage(list);
	}
	
	/**
     * 修改图片
     * 
     * @param image 图片信息
     * @return 结果
     */
	@Override
	public int updateImage(Image image) {
	    return imageMapper.updateImage(image);
	}

	/**
     * 删除图片对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteImageByIds(String ids) {
		return imageMapper.deleteImageByIds(Convert.toStrArray(ids));
	}

	@Override
	public int deleteImageById(String id) {
		int attachRow = imageAttachMapperExpand.deleteImageAttachByImageId(id);
		int row = imageMapper.deleteImageById(id);
		log.info("attachRow:{},row:{}",attachRow,row);
		return row;
	}

	@Override
	public List<Image> queryImagesByGoodsId(Long goodsId) {
		return imageMapperExpand.queryImagesByGoodsId(goodsId);
	}
}
